package jp.sourceforge.akjrcp.dropsomething2;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import jp.sourceforge.akjrcp.ui.GenericParameters;

public class GenericParameterSetting extends GenericParameters implements Setting,Cloneable{
	
	public GenericParameterSetting(Map<String, String> parameters){
		super(parameters);
	}
	
	public String toString(){
		return parametersToCsv(this);
	}
	
	public Object clone(){
		Map<String,String> map=getParameters();
		Map<String,String> newMap=new HashMap<String,String>();
		Iterator<String> iter=map.keySet().iterator();
		while(iter.hasNext()){
			String k=iter.next();
			newMap.put(new String(k), new String(map.get(k)));
		}
		GenericParameterSetting param=new GenericParameterSetting(newMap);
		return param;
	}

	@Override
	public boolean getBoolean(String key) {
		boolean ret=false;
		try{
			String v=getString(key);
			if(getString(key).equals("1")){
				v="true";
			}
			ret=Boolean.parseBoolean(v);
		}catch(Exception e){}
		return ret;
	}

	@Override
	public int getInt(String key) {
		int ret=0;
		try{
			ret=Integer.parseInt(getParameters().get(key));
		}catch(Exception e){}
		return ret;
	}

	@Override
	public String getString(String key) {
		return getParameters().get(key);
	}
	
}
